import defaultImg from '@/components/defaultImg/defaultImg.vue' //默认图片组件
import listCard from '@/components/acessory/listCard.vue' //列表卡片
import accessoryFilter from '@/components/down-filters/accessory-filter.vue'

export default {
  components: {
    defaultImg, //默认图片组件
    listCard,
    accessoryFilter, //条件筛选
  },
  data() {
    return {
      menu: [
        {
          icon: 'iconfabunew',
          text: '发布配件询价',
          url: '/pages_findAccessory/selectCarModel/selectCarModel'
        },{
          icon: 'iconwodexunjia',
          text: '我的询价',
          url: '/pages_findAccessory/myInquiryList/myInquiryList'
        },{
          icon: 'iconwodebaojia',
          text: '我的报价',
          url: '/pages_findAccessory/myQuoteList/myQuoteList'
        },{
          icon: 'iconwodedingdan',
          text: '我的订单',
          url: '/pages_order/accessoryOrder/accessoryOrderList/accessoryOrderList?tab=0'
        }
      ],
      isSticky: false, //是否吸顶
      list: [], //列表
      pageIndex: 1, //页码
      keyWords: '', //搜索关键字
      brandId: '', //搜索品牌
      baseRegionId: '', //市级id
      partCategoryId: '', //配件类目id
      sort: 0, //排序,0走默认排序，1=官寻，2=由近到远(lat、lon 必传)，3=发布时间降序排序
      showimg: false, //默认为空显示图片
      total: NaN, //总条数
      text: '',
      showText: false,

    }
  },
  computed: {
    lat(){
      return this.$store.state.latitude
    },
    lon(){
      return this.$store.state.longitude
    },
    systemInfo(){
      return uni.getSystemInfoSync()
    },

    scrollTop(){
      return (116 + 168 + 24 - 92 + 70) * this.systemInfo.windowWidth/750
    },
  },

  mounted() {
    this.getList()
  },
  onShow(){
    //清除历史数据
    this.$store.commit('accessory/cleanInfo')
  },
  onReachBottom() {
    this.getList()
  },
  methods: {
    //定位筛选
    openFillter() {
      console.log(this.scrollTop)
      if(!this.isSticky) {
        uni.pageScrollTo({
          scrollTop: this.scrollTop,
          duration: 300
        })
        this.isSticky = true
      }
    },
    //选择筛选
    fillterList(e){
      console.log(e)
      if(e.type === 0){
        //品牌选择
        this.brandId = e.id + ''
      } else if(e.type === 1){
        //分类选择
        this.partCategoryId = e.id ? e.id + '' : ''
      } else if(e.type === 2){
        //地区选择
        this.baseRegionId = e.id
      } else if(e.type === 3){
        //排序,0走默认排序，1=官寻，2=由近到远(lat、lon 必传)，3=发布时间降序排序
        this.sort = e.id
      }
      this.total = NaN
      this.pageIndex = 1
      this.showText = false
      this.showimg = false
      this.getList()
    },

    // 吸顶
    sticky(type) {
      this.isSticky = type
    },

    //点击搜索
    search() {
      this.total = NaN
      this.pageIndex = 1
      this.showText = false
      this.showimg = false
      this.getList()
    },
    // 列表
    getList() {
      if(this.showText){
        return false
      }
      uni.showLoading({
        title: '加载中'
      })
      this.$api.accessory.getCarPartListPaged({
        pageSize: 10,
        pageIndex: this.pageIndex,  //页码
        keyWords: this.keyWords, //搜索关键字
        configuration_Id: this.brandId, //搜索品牌
        partCategoryId: this.partCategoryId, //配件类目id
        baseRegionId: this.baseRegionId, //市级id
        lat: this.lat ? this.lat : 104.063364, //经度
        lon: this.lon ? this.lon : 30.566, //纬度
        sort: this.sort,
      }).then(res => {
        if(res.data.total === 0){
          this.total = res.data.total
          this.showimg = true
        } else {
          if(this.pageIndex === 1) {
            this.list = []
            this.list = res.data.list
            this.total = res.data.total
          }else {
            this.list = this.list.concat(res.data.list)
          }
          if(this.total <= this.pageIndex * 10){
            this.text = '-- 已经到底了 --'
            this.showText = true
          } else {
            this.pageIndex++
          }
        }
        uni.hideLoading()

      }).catch( e => {
        uni.hideLoading()
        // this.text = '加载失败，点击重新加载'
        // this.showText = true
      })
    },

    //发布寻车，我的寻车，我的报价
    fabuxcclick(url) {
      uni.navigateTo({
        url
      })
    },
    //跳转我要报价页面
    goOfferPage(findid) {
      uni.navigateTo({
        url: '/pages_dzr/R_offer/R_offer?findid=' + findid
      })
    },

  },
}
